package com.rong.controller;

import java.io.IOException;
import java.util.Enumeration;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class PageServlet extends HttpServlet
{
	private static final long serialVersionUID = -4359789813994056065L;

	public void doGet( HttpServletRequest request , HttpServletResponse response ) throws ServletException , IOException
	{
		doPost(request, response);
	}

	public void doPost( HttpServletRequest request ,HttpServletResponse response ) throws ServletException , IOException
	{
		String p = request.getParameter("p");
		if( null==request.getSession().getAttribute("loginUser"))
		{
			if( !"login".equals(p) )
			{
				response.sendRedirect("page?p=login");
				return;
			}	
		}	
		Enumeration<String> enums=request.getParameterNames();
		String key;
		while(enums.hasMoreElements())
		{
			key = enums.nextElement();
			request.setAttribute( key , request.getParameter( key ) );
		}
		request.getRequestDispatcher("WEB-INF/jsp/" + p +".jsp").forward(request, response);
	}

}
